package com.byit.controller;
/**
 * Created by marker on 2018/3/6.
 */

import com.byit.ueditor.ActionEnter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;

/**
 *
 * nginx代理访问例子
 *  http://localhost:8081/file/images/logo1.png
 *
 * @author marker
 *         create 2018-03-06 上午11:39
 **/
@Slf4j
@RestController
@RequestMapping("/api/ueditor")
public class ConfigUeditorController {



    /**
     *  ueditor 配置
     */
    @RequestMapping("/config")
    public void config(
            HttpServletRequest request,
            HttpServletResponse response) throws IOException {

        ServletContext application = request.getServletContext();

        request.setCharacterEncoding( "utf-8" );
        response.setHeader("Content-Type" , "text/html");

        String rootPath = this.getClass().getResource("/").getPath();

        log.debug("Ueditor Config rootPath {}", rootPath);
        Writer out = response.getWriter();


        out.write( new ActionEnter( request, rootPath ).exec() );
    }

}
